package com.zyong.design.pattern.observer.case2;

import java.util.ArrayList;
import java.util.List;

/**
 * @program: zyong-design-pattern
 * @ClassName: SubscriptionSubject
 * @author: zyong
 * @create: 2024-05-15 00:04
 */
public class SubscriptionSubject implements Subject {
    private List<Observer> weixinUserList = new ArrayList<>();

    @Override
    public void attach(Observer observer) {
        weixinUserList.add(observer);
    }

    @Override
    public void detach(Observer observer) {
        weixinUserList.remove(observer);
    }

    @Override
    public void notify(String message) {
        for (Observer observer : weixinUserList) {
            observer.update(message);
        }
    }
}
